package com.xywy.common.manager;

import java.util.Observable;
import java.util.Observer;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.xywy.R;
import com.xywy.common.BaseActivity;
import com.xywy.common.constants.ConstantValue;
import com.xywy.common.util.StringUtils;

/**
 * 底部导航栏管理类 Created by xgd on 2014/6/7.
 * 
 * @author xgd
 */
public class BottomManager implements Observer {
	private static final String TAG = "BottomManager";

	private BottomManager() {
	}

	public static BottomManager getInstance() {
		return SingletonHolder.instance;
	}

	public static class SingletonHolder {
		private static BottomManager instance = new BottomManager();
	}

	private LinearLayout ll_main;

	private ImageView iv_wjk;
	private ImageView iv_jtys;
	private ImageView iv_find;
	// private ImageView iv_me;

	private TextView tv_wjk;
	private TextView tv_jtys;
	private TextView tv_find;
	// private TextView tv_me;

	protected BaseActivity mActivity;

	public void init(BaseActivity activity) {

		this.mActivity = activity;

		ll_main = (LinearLayout) activity.findViewById(R.id.ll_main_bottom);
		iv_wjk = (ImageView) activity.findViewById(R.id.iv_bottom_wjk);
		iv_jtys = (ImageView) activity.findViewById(R.id.iv_bottom_jtys);
		iv_find = (ImageView) activity.findViewById(R.id.iv_bottom_find);
		// iv_me = (ImageView) activity.findViewById(R.id.iv_bottom_me);

		tv_wjk = (TextView) activity.findViewById(R.id.tv_bottom_wjk);
		tv_jtys = (TextView) activity.findViewById(R.id.tv_bottom_jtys);
		tv_find = (TextView) activity.findViewById(R.id.tv_bottom_find);
		// tv_me = (TextView) activity.findViewById(R.id.tv_bottom_me);
	}

	private int id;

	@Override
	public void update(Observable observable, Object data) {

		// 控制底部导航栏变动
		if (!StringUtils.isBlank(data.toString())) {
			id = Integer.parseInt(data.toString());
			showCommonBottom(id);
		}
	}

	/**
	 * FG_WJK,FG_JTYS,FG_FIND、FG_ME 底部导航
	 * 
	 * @param id
	 */
	int greenColor;

	public void showCommonBottom(int id) {
		greenColor = mActivity.getResources().getColor(R.color.start_bt_bg);
		clearBottomBar();
		switch (id) {
		case ConstantValue.FG_WJK:
			showwjkBottom();
			break;
		// case ConstantValue.FG_JTYS:
		// showJTYSBottom();
		// break;
		case ConstantValue.FG_FIND:
			showFindBottom();
			break;
		case ConstantValue.FG_FWC:
			showJTYSBottom();
			break;
		// case ConstantValue.FG_ME:
		// showMeBottom();
		// break;
		}

	}

	/**
	 * 分别展示底部导航选中效果
	 */
	/**
	 * 微健康
	 */
	private void showwjkBottom() {
		changeBottomVisiblity(View.VISIBLE);
		iv_wjk.setBackgroundResource(R.drawable.main_wjk_pressed);
		tv_wjk.setTextColor(greenColor);
	}

	/**
	 * 家庭医生
	 */
	private void showJTYSBottom() {
		changeBottomVisiblity(View.VISIBLE);

		iv_jtys.setBackgroundResource(R.drawable.main_jtys_pressed);
		tv_jtys.setTextColor(greenColor);
	}

	/**
	 * 发现
	 */
	private void showFindBottom() {
		changeBottomVisiblity(View.VISIBLE);
		iv_find.setBackgroundResource(R.drawable.main_fx_pressed);
		tv_find.setTextColor(greenColor);
	}

	/**
	 * 我
	 */
	// private void showMeBottom() {
	// changeBottomVisiblity(View.VISIBLE);
	// iv_me.setBackgroundResource(R.drawable.main_wo);
	// tv_me.setTextColor(greenColor);
	// }

	/**
	 * 清空bottombar按下效果
	 */

	private void clearBottomBar() {
		iv_wjk.setBackgroundResource(R.drawable.main_wjk);
		iv_jtys.setBackgroundResource(R.drawable.main_jtys);
		iv_find.setBackgroundResource(R.drawable.main_fx);
		// iv_me.setBackgroundResource(R.drawable.main_wo_pressed);

		// int whiteColor = mActivity.getResources().getColor(R.color.white);
		int bottom_font_color = mActivity.getResources().getColor(R.color.yjk_bottom_font_color);
		tv_wjk.setTextColor(bottom_font_color);
		tv_jtys.setTextColor(bottom_font_color);
		tv_find.setTextColor(bottom_font_color);
		// tv_me.setTextColor(Color.WHITE);
	}

	/**
	 * 改变底部导航容器显示情况
	 */
	public void changeBottomVisiblity(int type) {
		if (ll_main.getVisibility() != type)
			ll_main.setVisibility(type);
	}
}
